package com.wannengbang.storemobile.homepage;


import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.base.BaseActivity;
import com.wannengbang.storemobile.base.DataCallBack;
import com.wannengbang.storemobile.bean.HuaBeiOrderBean;
import com.wannengbang.storemobile.dialog.HuaBeiStagesDialog;
import com.wannengbang.storemobile.homepage.model.HomePageModelImpl;
import com.wannengbang.storemobile.homepage.model.IHomePageModel;
import com.wannengbang.storemobile.utils.CashierInputFilter;
import com.wannengbang.storemobile.utils.FastClickUtils;
import com.wannengbang.storemobile.utils.ToastUtil;
import com.wannengbang.storemobile.widget.ViewLoading;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HuaBeiStagesActivity extends BaseActivity {
    @BindView(R.id.edit_money)
    EditText editMoney;
    @BindView(R.id.tv_commit)
    TextView tvCommit;
    private IHomePageModel homePageModel;
    private String moneyUnit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hua_bei_stages);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        homePageModel = new HomePageModelImpl();
        InputFilter[] filters = {new CashierInputFilter()};
        editMoney.setFilters(filters);
    }

    @OnClick(R.id.tv_commit)
    public void onViewClicked() {
        if (FastClickUtils.isFastClick()) {
            return;
        }
        String money = editMoney.getText().toString();
        if (TextUtils.isEmpty(money)) {
            ToastUtil.showShort("请输入金额");
            return;
        }
        requestStoreOrderAdd();
    }

    private void requestStoreOrderAdd() {
        String money = editMoney.getText().toString();
        //钱数 单位分
        moneyUnit = String.valueOf(Double.parseDouble(money) * 100);
        moneyUnit = moneyUnit.substring(0, moneyUnit.indexOf("."));
        ViewLoading.showProgress(mActivity, "收款中......");
        homePageModel.requestAddHuaBeiOrder(moneyUnit, new DataCallBack<HuaBeiOrderBean>() {
            @Override
            public void onSuccessful(HuaBeiOrderBean bean) {
                String payUrl = bean.getData();
                HuaBeiStagesDialog dialog = HuaBeiStagesDialog.newInstance(payUrl);
                dialog.show(getSupportFragmentManager(), "dialog");
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }
}
